import json

from django.shortcuts import render
from django.http import JsonResponse

# Create your views here.
from django.views import View


class LoginView(View):

    def get(self, req):

        return render(req, 'login.html')

    def post(self, req):
        pass


class ReceiveView(View):

    def get(self, req):

        # 1 接收参数
        data = req.GET
        username = data.get('username')
        pw = data.get('pw')

        return JsonResponse({'info':{'username':username}})

    def post(self, req):
        # json数据在body中 用body取
        data_json = req.body.decode()
        data = json.loads(data_json)
        username = data.get('username')
        pw = data.get('pw')
        # return JsonResponse({'info':{'username': username}})
        return JsonResponse({'info': {'username': username}})
